<?php
final class RegisterFormValidator {

    public static function validate($post) {
        
        $errors = array();

        $userName = $post["userName"];
        $mobileNumber = $post["mobileNumber"];

        if (empty($userName)) {
            $errors[] = "User name is required.";
        } else {
            $userService = ServiceFactory::getUserService();
            $isAvailable = $userService->checkIfUserNameIsAvailable($userName);
            if (!$isAvailable){
                $errors[] = "User name is not available. Please choose a different one.";
            }
        }

        if (empty($mobileNumber)) {
            $errors[] = "Mobile number is required.";
        }

        if (sizeof($errors) == 0) {
            $errors = null;
        }

        return $errors;

    }

}
?>
